package com.aios.dao;

import com.aios.entity.Switch;
import com.aios.entity.SwitchExample;
import com.aios.entity.SwitchPanel;
import com.aios.entity.mapper.SwitchTimer;



import java.util.List;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

public interface SwitchMapper {
    
    int countByExample(SwitchExample example);

    
    int deleteByExample(SwitchExample example);

    
    int deleteByPrimaryKey(String id);

    
    int insert(Switch record);

   
    int insertSelective(Switch record);

    
    List<Switch> selectByExample(SwitchExample example);

    
    Switch selectByPrimaryKey(String id);

    
    int updateByExampleSelective(@Param("record") Switch record, @Param("example") SwitchExample example);

    
    int updateByExample(@Param("record") Switch record, @Param("example") SwitchExample example);

    
    int updateByPrimaryKeySelective(Switch record);

   
    int updateByPrimaryKey(Switch record);

	@Select("SELECT * FROM switch WHERE SWITCH_PANEL_ID=(SELECT SWITCH_PANEL_ID FROM switch WHERE ID=#{id})")
   	@ResultMap(value="MiniResultMap")
	List<Switch> findBySwitchPanel(String id);

	@Select("SELECT * FROM switch WHERE SWITCH_PANEL_ID=#{id}")
	@ResultMap(value = "MiniResultMap")
	List<Switch> findAllBySwitchPanelId(@Param("id") String id);

	@Select("SELECT s.NAME FROM switch s,system_user_has_switch_panel suhsp WHERE s.SWITCH_PANEL_ID=suhsp.SWITCH_PANEL_ID  AND s.ID != #{id} AND s.NAME = #{name} AND suhsp.SYSTEM_USER_ID = #{userId}")
	@ResultMap(value = "MiniResultMap")
	List<Switch> findByNameNotWithId(@Param("id") String id, @Param("name") String name,
			@Param("userId") String userId);


 	@Select("SELECT s.ID,s.SWITCH_PANEL_ID,s.CONTROLLER_RECEIVER,t.SWITCH_SETTING from timer as t,day_schedule as d,switch as s where t.ID = d.TIMER_ID AND s.ID=t.SWITCH_ID  AND  d.DAY_OF=#{day} AND triger_time BETWEEN #{min} AND #{max} AND t.STATUS=1")
	@ResultMap(value="SwitchTimerMap")
	List<SwitchTimer> findByDayTimeAndTime(@Param("day") int day,@Param("min") int min,@Param("max") int max);
	


}